<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>update-problem</title>
    <link rel="stylesheet" href="http://unpkg.com/layui@2.6.8/dist/css/layui.css">
</head>

<script src="http://unpkg.com/layui@2.6.8/dist/layui.js"></script>

<body>
    <form class="layui-form" action="" method="post">
        <div class="layui-form-item">
            {{ if .update }}
            <div class="layui-inline">
                <label class="layui-form-label">题号</label>
                <div class="layui-input-block">
                    <input type="text" id="problem_id" name="problem_id" lay-verify="title" autocomplete="off" class="layui-input" value="{{ .problem.ProblemId }}" readonly>
                </div>
            </div>
            {{ end }}
            <div class="layui-inline">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-block">
                    <input type="text" id="title" name="title" lay-verify="title" autocomplete="off" class="layui-input" value="{{ .problem.Title }}">
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" id="description" name="description" class="layui-textarea">{{ .problem.Description }}</textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">输入描述</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" id="desc_input" name="desc_input" class="layui-textarea">{{ .problem.DescInput }}</textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">输出描述</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" id="desc_output" name="desc_output" class="layui-textarea">{{ .problem.DescOutput }}</textarea>
            </div>
        </div>
        {{ range $i, $v := .stdins }}
        <div class="layui-form-item" name="example">
            <div class="layui-col-xs10 layui-col-sm10 layui-col-md5">
                <label class="layui-form-label">标准输入</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" id="stdin" name="stdin" class="layui-textarea">{{ index $.stdins $i }}</textarea>
                </div>
            </div>
            <div class="layui-col-xs10 layui-col-sm10 layui-col-md5">
                <label class="layui-form-label">标准输出</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" id="stdout" name="stdout" class="layui-textarea">{{ index $.stdouts $i }}</textarea>
                </div>
            </div>
            <div class="layui-col-xs1 layui-col-sm1 layui-col-md1">
                <center>
                    <button class="layui-btn layui-btn-sm" type="button" id="insert" style="margin: auto;vertical-align: middle;" onclick="insert_example(this);">
                        <i class="layui-icon layui-icon-addition"></i>
                    </button>
                </center>
            </div>
            <div class="layui-col-xs1 layui-col-sm1 layui-col-md1">
                <center>
                    <button class="layui-btn layui-btn-danger layui-btn-sm" type="button" id="remove" style="margin: auto;vertical-align: middle;" onclick="remove(this);">
                        <i class="layui-icon layui-icon-delete"></i>
                    </button>
                </center>
            </div>
        </div>
        {{ else }}
        <div class="layui-form-item" name="example">
            <div class="layui-col-xs10 layui-col-sm10 layui-col-md5">
                <label class="layui-form-label">标准输入</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" id="stdin" name="stdin" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-col-xs10 layui-col-sm10 layui-col-md5">
                <label class="layui-form-label">标准输出</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" id="stdout" name="stdout" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-col-xs1 layui-col-sm1 layui-col-md1">
                <center>
                    <button class="layui-btn layui-btn-sm" type="button" id="insert" style="margin: auto;vertical-align: middle;" onclick="insert_example(this);">
                        <i class="layui-icon layui-icon-addition"></i>
                    </button>
                </center>
            </div>
            <div class="layui-col-xs1 layui-col-sm1 layui-col-md1">
                <center>
                    <button class="layui-btn layui-btn-danger layui-btn-sm" type="button" id="remove" style="margin: auto;vertical-align: middle;" onclick="remove(this);">
                        <i class="layui-icon layui-icon-delete"></i>
                    </button>
                </center>
            </div>
        </div>
        {{ end }}
        <div class="layui-form-item" id="limits">
            <div class="layui-inline">
                <label class="layui-form-label">时间限制</label>
                <div class="layui-input-inline">
                    <input type="number" id="time_limit" name="time_limit" autocomplete="off" class="layui-input" value="{{ .problem.TimeLimit }}">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">内存限制</label>
                <div class="layui-input-inline">
                    <input type="number" id="memory_limit" name="memory_limit" autocomplete="off" class="layui-input" value="{{ .problem.MemoryLimit }}">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">误差范围</label>
                <div class="layui-input-inline">
                    <input type="number" id="eps" name="eps" lay-verify="email" autocomplete="off" class="layui-input" value="{{ .problem.Eps }}">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">初始化文件映射</label>
                <div class="layui-input-inline">
                    <input type="text" id="data_ref_id" name="init_ref_id" autocomplete="off" class="layui-input" value="{{ .problem.InitRefId }}">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">题目文件映射</label>
                <div class="layui-input-inline">
                    <input type="text" id="data_ref_id" name="data_ref_id" autocomplete="off" class="layui-input" value="{{ .problem.DataRefId }}">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">特判文件映射</label>
                <div class="layui-input-inline">
                    <input type="text" id="spj_ref_id" name="spj_ref_id" autocomplete="off" class="layui-input" value="{{ .problem.SpjRefId }}">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">判题类型</label>
            <div class="layui-input-inline">
                <select name="judge_type" id="judge_type" lay-verify="">
                    <option value="0" {{ if eq .problem.JudgeType 0 }} selected {{ end }}>常规判题</option>
                    <option value="1" {{ if eq .problem.JudgeType 1 }} selected {{ end }}>交互判题</option>
                    <option value="2" {{ if eq .problem.JudgeType 2 }} selected {{ end }}>特判题</option>
                    <option value="3" {{ if eq .problem.JudgeType 3 }} selected {{ end }}>数据库查询题型</option>
                    <option value="4" {{ if eq .problem.JudgeType 4 }} selected {{ end }}>数据库增删改题型</option>
                    <option value="5" {{ if eq .problem.JudgeType 5 }} selected {{ end }}>模块题型</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">比对模式</label>
            <div class="layui-input-block">
                <input type="checkbox" name="compare_flag" title="严格一致" value="0" {{ if eq .problem.CompareFlag 0 }} checked {{ end }}>
                <input type="checkbox" name="compare_flag" title="精度误差" value="2" {{ if intAndint .problem.CompareFlag 2 }} checked {{ end }}>
                <input type="checkbox" name="compare_flag" title="忽略行末空格" value="4" {{ if intAndint .problem.CompareFlag 4 }} checked {{ end }}>
                <input type="checkbox" name="compare_flag" title="忽略所有空白符" value="8" {{ if intAndint .problem.CompareFlag 8 }} checked {{ end }}>
                <input type="checkbox" name="compare_flag" title="忽略大小写" value="16" {{ if intAndint .problem.CompareFlag 16 }} checked {{ end }}>
                <input type="checkbox" name="compare_flag" title="忽略列表顺序" value="32" {{ if intAndint .problem.CompareFlag 32 }} checked {{ end }}>
                <input type="checkbox" name="compare_flag" title="比对json对象" value="128" {{ if intAndint .problem.CompareFlag 128 }} checked {{ end }}>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">赛制</label>
            <div class="layui-input-block">
                <input type="checkbox" name="ruler" title="ACM" value="1" {{ if intAndint .problem.Ruler 1 }} checked {{ end }}>
                <input type="checkbox" name="ruler" title="OI" value="2" {{ if intAndint .problem.Ruler 2 }} checked {{ end }}>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">结果集</label>
            <div class="layui-input-block">
                <input type="checkbox" name="query_set" title="返回首次输出" value="1" {{ if intAndint .problem.QuerySet 1 }} checked {{ end }}>
                <input type="checkbox" name="query_set" title="返回首次错误输出" value="2" {{ if intAndint .problem.QuerySet 2 }} checked {{ end }}>
                <input type="checkbox" name="query_set" title="返回首次错误输入" value="4" {{ if intAndint .problem.QuerySet 4 }} checked {{ end }}>
                <input type="checkbox" name="query_set" title="返回首次错误对应的正确输出" value="8" {{ if intAndint .problem.QuerySet 8 }} checked {{ end }}>
                <input type="checkbox" name="query_set" title="返回所有结果信息" value="16" {{ if intAndint .problem.QuerySet 16 }} checked {{ end }}>
                <input type="checkbox" name="query_set" title="返回所有用户输出" value="32" {{ if intAndint .problem.QuerySet 32 }} checked {{ end }}>
                <input type="checkbox" name="query_set" title="返回所有正确输出" value="64" {{ if intAndint .problem.QuerySet 64 }} checked {{ end }}>
            </div>
        </div>
        <div class="layui-form-item">
            <center>
                <input class="layui-btn" name="subumit" type="submit" id="submit" style="margin: auto;" value="保存题目" />
            </center>
        </div>
    </form>
</body>
<script>
    function insert_example(node) {
        if (document.getElementsByName("example").length >= 5) {
            alert("最多五个测试用例来帮助用户理解题目,再多就不礼貌了");
            return;
        }
        p = node.parentNode.parentNode.parentNode;
        pp = p.parentNode;
        before = document.getElementById("limits");
        pp.insertBefore(p.cloneNode(true), before);
    }

    function remove(node) {
        if (document.getElementsByName("example").length <= 1) {
            alert("请至少保留一个测试用例来帮助用户理解题目");
            return;
        }
        node.parentNode.parentNode.parentNode.remove();
    }
</script>

</html>